'''
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with self work for additional information
 * regarding copyright ownership.  The ASF licenses self file
 * to you under the Apache License, Version 2.0 (the
 * "License") you may not use self file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
'''
from base.graph.Node_Fluid import Node_Fluid

'''
 * "variable" nodes these are outside the RDF2003 specification, but are
 * used internally for "placeholder" nodes where blank nodes would be
 * wrong, most specifically in Query.
'''

class Node_Variable(Node_Fluid):

    '''
     * Initialise self Node_Variable from a string <code>name</code>,
     * which becomes wrapped in a VariableName.
    '''
    # param String name:
    def __init__(self, name):
        super().__init__(self.VariableName(name))
    

    #@Override
    # param 
    # result String
    def getName(self):
        # return ((VariableName) label).name
        return self.label.name

    

    #@Override
    # param NodeVisitor v
    # result Object
    def visitWith(self, v):
        return v.visitVariable(self, self.getName())
    

    #@Override
    # param 
    # result boolean
    def isVariable(self):
        return True
    

    #@Override
    # param 
    # result String
    def toString(self):
        return self.label.toString()
    

    #@Override
    # param Object other
    # result boolean
    def equals(self, other):
        if (self == other):
            return True
        #return other instanceof Node_Variable and label.equals(((Node_Variable) other).label)
        return isinstance(other, Node_Variable) and self.label.equals(other.label)


    # param String name
    # result static Object
    def variable(self, name):
        return self.VariableName(name)
    

    class VariableName:
        def __init__(self, name):
            self.name = name

        #@Override
        # param
        # result int
        def hashCode(self):
            return self.name.hashCode()
        

        #@Override
        # param Object other
        # result boolean
        def equals(self, other):
            if (self == other):
                return True
            #return other instanceof VariableName and name.equals(((VariableName) other).name)
            return isinstance(other, self.__class__) and self.name == other.name


        #@Override
        # param
        # result String
        def toString(self):
            return "?" + self.name
        
    


